Repository navigation
A20: Clear owned password hashing buffers - #2849
Conversation
|
stevehu
left a comment
There was a problem hiding this comment.
Code review (A20 password hashing buffers). One finding inline; the change is otherwise fine. The same comment applies to the master/2.x counterpart.
| } | ||
| try { | ||
| SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); | ||
| byte[] hash = skf.generateSecret(spec).getEncoded(); |
There was a problem hiding this comment.
[nit] The PBKDF2 SecretKey keeps a password copy that can't be destroyed. generateSecret(spec) returns a PBKDF2KeyImpl that holds its own clone of the password in passwd, plus an HMAC keyed with the password. spec.clearPassword() doesn't touch either one, and destroy() throws DestroyFailedException. Checked on JDK 25 via reflection: passwd still holds the password after clearPassword(). It's zeroed only when the Cleaner runs after GC. The same applies at line 163 in validatePassword.
Fix: record this as a provider-owned copy in the A20 assessment, or compute PBKDF2 with a Mac over bytes you own if this copy must be ruled out.



Clear the temporary password array and the PBEKeySpec copies in hashing and verification. Preserve the stored hash format and caller ownership of the verifier input.
All four focused HashUtil tests passed locally on master.